import java.util.Date;


public class TimeSheet {
	
	private static final long DAY_TO_MILLISECOND  	= 86400000L; // 1000 * 60 * 60 * 24
	private static final long HOUR_TO_MILLISECOND 	= 3600000L; //1000 * 60 * 60
	private static final long MINUTE_TO_MILLISECOND 	= 60000L; // 1000 * 60
	private static final long SECOND_TO_MILLISECOND 	= 1000L;

	private int days;
	private int hours;
	private int minutes;
	private int seconds;
	
	public TimeSheet(int days, int hours, int minutes, int seconds) {
		this.days = days;
		this.hours = hours;
		this.minutes = minutes;
		this.seconds = seconds;
	}
	
	public TimeSheet(TimeSheet other) {
		this(other.getDays(),
				other.getHours(),
				other.getMinutes(),
				other.getSeconds());

	}
	
	public TimeSheet() {
		this(0,0,0,0);
	}
	
	public static TimeSheet getTimeSheetFrom(long millisecondTime) {
		int days 	= (int) (millisecondTime / DAY_TO_MILLISECOND);		
		millisecondTime = millisecondTime % DAY_TO_MILLISECOND;
		
		int hours 	= (int) (millisecondTime / HOUR_TO_MILLISECOND);
		millisecondTime = millisecondTime % HOUR_TO_MILLISECOND;
		
		int minutes = (int) (millisecondTime / MINUTE_TO_MILLISECOND);
		millisecondTime = millisecondTime % MINUTE_TO_MILLISECOND;
		
		int seconds = (int) (millisecondTime / SECOND_TO_MILLISECOND);
		
		return new TimeSheet(days, hours, minutes, seconds);
	}
	
	public static TimeSheet interval(Date start, Date end) {
		long millisecondTime = end.getTime() - start.getTime();
		return getTimeSheetFrom(millisecondTime);
	}	
	
	public static TimeSheet sum(Date one, Date other) {
		long millisecondTime = one.getTime() + other.getTime();
		return getTimeSheetFrom(millisecondTime);
	}
	
	public static TimeSheet sum(TimeSheet one, TimeSheet other) {
		long millisecondTime = one.getMilliseconds() + other.getMilliseconds();
		return TimeSheet.getTimeSheetFrom(millisecondTime);
	}
	
	public long getMilliseconds() {
		long time = this.days * DAY_TO_MILLISECOND +
					this.hours * HOUR_TO_MILLISECOND +
					this.minutes * MINUTE_TO_MILLISECOND + 
					this.seconds * SECOND_TO_MILLISECOND;
		return time;
	}
	
	@Override
	public String toString() {
		// TODO Auto-generated method stub
		return "(D : " 		+ days 		+ 
				", H : " 	+ hours 	+ 
				", M : " 	+ minutes 	+ 
				", S : " 	+ seconds + ")";
	}
	
	public int getDays() {
		return days;
	}

	public int getHours() {
		return hours;
	}

	public int getMinutes() {
		return minutes;
	}

	public int getSeconds() {
		return seconds;
	}
}
